<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" >
<ui:composition template="/templates/principal.xhtml" >
<ui:define name="corpo">
<p:growl id="mensagens" globalOnly="true" />
<p:panel header="Usuário" style="text-align: center; height: 880px; padding: 0px; font-size: 16px" >
    <h:form prependId="false" style="text-align: left;" >
        <h:inputHidden value="#{usuarioBean.usuario.idusuario}" />
        <h:inputHidden value="#{usuarioBean.senhaCriptografada}" />
        <p:fieldset legend="Dados do usuário" style="font-size: 12px">    
            <h:panelGrid id="dadosUsuario" columns="3" cellpadding="2" width="950" style="text-align: left; " >
            <h:outputLabel value="Saram:" for="saram" />
            <h:inputText id="saram" value="#{usuarioBean.usuario.saram}" size="45" maxlength="8" disabled="true" />
            <br />
            <h:outputLabel value="Nome completo: " for="nome" />
            <h:inputText id="nome" value="#{usuarioBean.usuario.pessoa.nome}" required="true" size="45" validatorMessage="Campo Nome completo deve conter pelo menos 3 caracteres!" requiredMessage="Campo Nome completo obrigatório!" maxlength="80" disabled="#{usuarioBean.permiteAlterarSupervisor}" >
                <f:validateLength minimum="3" />
                <p:ajax event="blur" update="nomeMessage"  />
            </h:inputText>
            <h:message id="nomeMessage" for="nome" style="color: red; font-size: 11px"/>
            <h:outputLabel value="Nome de guerra:" for="nomeGuerra" />
            <h:inputText id="nomeGuerra" value="#{usuarioBean.usuario.pessoa.nomeGuerra}" required="true" size="45" validatorMessage="Campo Nome de guerra deve conter pelo menos 3 caracteres!" requiredMessage="Campo Nome de guerra obrigatório!" maxlength="40" disabled="#{usuarioBean.permiteAlterarSupervisor}" >
                <f:validateLength minimum="3" />
                <p:ajax event="blur" update="nomeGuerraMessage"  />
            </h:inputText>
            <h:message id="nomeGuerraMessage" for="nomeGuerra" style="color: red; font-size: 11px" />
            <h:outputLabel value="Identidade militar" for="idm" />
            <h:inputText id="idm" value="#{usuarioBean.usuario.pessoa.identidadeMilitar}" size="45" maxlength="20" />
            <br/>
            <h:outputLabel value="Função:" for="funcao" />
            <h:inputText id="funcao" value="#{usuarioBean.usuario.pessoa.funcao}" size="45" maxlength="255" />
            <br/>
            <h:outputLabel value="Posto/Graduação:" for="postgrad" />
            <h:selectOneMenu  id="postgrad" value="#{usuarioBean.usuario.pessoa.postoGraduacao}" >
                <f:selectItems value="#{usuarioBean.postoGraduacao}" var="item" itemValue="#{item.description}" itemLabel="#{item.value}" />
            </h:selectOneMenu>
            <br/>
            <h:outputLabel value="Unidade:" for="unidade" />
            <h:selectOneMenu  id="unidade" value="#{usuarioBean.usuario.pessoa.unidade}" valueChangeListener="#{setorBean.selecionaSetorPorOM}" required="true" requiredMessage="Campo Unidade obrigatório!" validator="validaOMId" >
                <f:selectItem itemValue="-1" itemLabel="Selecione" />
                <f:selectItems value="#{unidadeMilitarBean.listarTipos}" var="it" itemValue="#{it.value}" itemLabel="#{it.key}" />
                <f:ajax execute="@this" render="setor" event="change" />
            </h:selectOneMenu>
            <br/>
            <h:outputLabel value="Setor: " for="setor" />
            <h:selectOneMenu id="setor" value="#{usuarioBean.usuario.pessoa.setor}" required="true" requiredMessage="Campo Setor obrigatório!" validator="validaSetorId" >
                <f:selectItems value="#{setorBean.listarSetorPorOm}" var="item" itemValue="#{item.idsetor}" itemLabel="#{item.descricaoSetor}" />
                <p:ajax event="blur" update="setorMessage" />
            </h:selectOneMenu>
            <h:message id="setorMessage" for="setor" style="color: red; font-size: 11px" />  
            <h:outputLabel value="E-mail funcional (intraer):" for="emailFuncional" />
            <h:inputText id="emailFuncional" value="#{usuarioBean.usuario.pessoa.emailComercial}" required="true" size="45" maxlength="255" validatorMessage="E-mail funcional inválido!" requiredMessage="Campo E-mail funcional obrigatório!" style="text-transform: lowercase;" >
                <f:validateRegex pattern="[a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9\-\_\.]+" />
                <p:ajax event="blur" update="emailFMessage"  />
            </h:inputText>
            <h:message id="emailFMessage" for="emailFuncional" style="color: red; font-size: 11px" />  
            <h:outputLabel value="E-mail pessoal:" for="emailPessoal" />
            <h:inputText id="emailPessoal" value="#{usuarioBean.usuario.pessoa.emailPessoal}" size="45" maxlength="255" validatorMessage="E-mail pessoal inválido!" style="text-transform: lowercase;" >
                <f:validateRegex pattern="[a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9\-\_\.]+" />
            </h:inputText>
            <h:message id="emailPMessage" for="emailPessoal" style="color: red; font-size: 11px" /> 
            <h:outputLabel value="Telefone:" for="tel"/>
            <p:inputMask id="tel" value="#{usuarioBean.usuario.pessoa.telComercial}" size="12" mask="(999)9999-9999" />
            <br/>

            <h:outputLabel value="Login:" for="login" />
            <h:inputText id="login" value="#{usuarioBean.usuario.login}" required="true" validatorMessage="Campo Login deve conter pelo menos 3 caracteres!" size="45" requiredMessage="Campo Login obrigatório!"  maxlength="80" disabled="#{usuarioBean.habilitaCampo or usuarioBean.permiteAlterarSupervisor}" >
                <f:validateLength minimum="3" />
                <p:ajax event="blur" update="loginMessage"  />
            </h:inputText>
            <h:message id="loginMessage" for="login" style="color: red; font-size: 11px"/> 
            <h:outputLabel value="Senha:" for="senha" />
            <h:inputSecret id="senha" value="#{usuarioBean.usuario.senha}" maxlength="60" size="45" redisplay="false" rendered="true" validatorMessage="Campo Senha deve conter pelo menos 6 caracteres!" >
                <f:validateLength minimum="6" />
            </h:inputSecret>
            <h:message id="senhaMessage" for="senha" style="color: red; font-size: 11px" />
            <h:outputLabel value="Confirmar senha:" for="confirmarSenha" />
            <h:inputSecret id="confirmarSenha" value="#{usuarioBean.confirmarSenha}" maxlength="60" size="45" />
            <h:message id="confirmarSenhaMessage" for="confirmarSenha" style="color: red; font-size: 11px" />
            <h:outputLabel value="Permissão:" for="permissao" />
            <h:selectOneMenu id="permissao" value="#{usuarioBean.usuario.permissao}" disabled="#{usuarioBean.habilitaCampo or usuarioBean.permiteAlterarSupervisor}" >
                <f:selectItem itemValue="ROLE_CONVENCIONAL" itemLabel="Convencional" />
                <f:selectItem itemValue="ROLE_PROTOCOLISTA" itemLabel="Protocolista"  />
                <f:selectItem itemValue="ROLE_ADMINISTRADOR" itemLabel="Administrador"  />
                <f:ajax execute="@this" render="dadosUsuario" event="change" />
            </h:selectOneMenu> 
            <br/>
            <h:outputLabel for="ativo" value="Ativo:" />
            <h:selectOneMenu id="ativo" value="#{usuarioBean.usuario.ativo}" disabled="#{usuarioBean.habilitaCampo or usuarioBean.permiteAlterarSupervisor}" >
                <f:selectItem itemValue="true" itemLabel="Sim" />
                <f:selectItem itemValue="false" itemLabel="Não" />
            </h:selectOneMenu>
            <br/>
            <h:outputLabel value="Tramita:" for="tramita"  />
            <h:selectOneMenu id="tramita" value="#{usuarioBean.usuario.tramita}" disabled="#{usuarioBean.habilitaCampo or usuarioBean.permiteAlterarSupervisor}" >
                <f:selectItem itemValue="true" itemLabel="Sim" />
                <f:selectItem itemValue="false" itemLabel="Não" />
            </h:selectOneMenu>
            <br />
            <h:outputLabel value="Data cadastramento:" for="dataCadastramento" />
            <h:outputText id="dataCadastramento" value="#{usuarioBean.usuario.dataCadastramento}" style="font-weight: bold">
                <f:convertDateTime dateStyle="medium" />
            </h:outputText>
            <br/>
            <h:outputLabel value="Termo de responsabilidade:" for="termo" />
            </h:panelGrid>
            <h:outputLabel />
            <h:outputLabel />
            <h:panelGroup>
                <h:inputTextarea id="termo" cols="60" rows="8" disabled="true" value="#{configuracaoBean.termo}" />
            </h:panelGroup>

            <br />
            <h:panelGroup>
                <p:commandButton action="#{usuarioBean.salvar}" value="Salvar" ajax="false" update="dadosUsuario, nomeMessage, saramMessage, emailFMessage, emailPMessage, nomeGuerraMessage, loginMessage, senhaMessage, confirmarSenhaMessage, mensagens" image="ui-icon ui-icon-disk" disabled="#{usuarioBean.habilitaBotaoSalvar}"  />
                <p:commandButton onclick="history.back()" value="Voltar" immediate="true" image="ui-icon ui-icon-arrowreturnthick-1-w"  />
            </h:panelGroup>
        </p:fieldset>
    </h:form>
</p:panel>
</ui:define>
</ui:composition>
</html>
